package com.dailyblue.java.spring.boot.shopping.controller;

import com.dailyblue.java.spring.boot.commons.bean.JsonResult;
import com.dailyblue.java.spring.boot.commons.bean.ResultTool;
import com.dailyblue.java.spring.boot.shopping.bean.Goods;
import com.dailyblue.java.spring.boot.shopping.service.GoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/goods")
@CrossOrigin
public class GoodsController {
    @Resource
    private GoodsService goodsHashServiceImpl;

    @GetMapping
    public JsonResult find() {
        return goodsHashServiceImpl.findAll();
    }

    @GetMapping("/add/{id}")
    public JsonResult add(@PathVariable Integer id) {
        return goodsHashServiceImpl.add(id);
    }

    @GetMapping("/cart")
    public JsonResult cart() {
        return goodsHashServiceImpl.findAllGwc();
    }

    @DeleteMapping("/delete/{id}")
    public JsonResult deleteById(@PathVariable Integer id) {
        return goodsHashServiceImpl.deleteById(id);
    }

    @PutMapping("/update/{id}/{num}")
    public JsonResult updateCartNum(@PathVariable("id") Integer id, @PathVariable("num") Integer num) {
        return goodsHashServiceImpl.updateCartNum(id, num);
    }
}
